Load in all of the files by setting the working directory and making a list of filenames to grab Add the Date and View of the trail to seperate columns using the character string of the filename
rm(list=ls(all=TRUE))
setwd("~/Post-doc/Data/Processed MatLab Files")
The working directory was changed to C:/Users/nicoleh3/Documents/Post-doc/Data/Processed MatLab Files inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.
path <- "C:\\Users\\nicoleh3\\Documents\\Post-doc\\Data\\Processed MatLab Files\\"
files <- list.files(path=path, pattern="*.csv")
ldf = lapply(files, function(x) {
dat = read.table(x, header=T, sep=",")
# Add column names
names(dat) = c('X', 'Y', 'Z', 'Track')
# Add a column with the Date of the trial
dat$Date = substr(x,1,8)
# Add a column with the View of the trial
dat$View = substr(x,14,15)
# Add a column with the filename
dat$File.name = substr(x,1,15)
return(dat)
})
library(dplyr)
package 㤼㸱dplyr㤼㸲 was built under R version 3.6.3
Attaching package: 㤼㸱dplyr㤼㸲
The following objects are masked from 㤼㸱package:stats㤼㸲:
filter, lag
The following objects are masked from 㤼㸱package:base㤼㸲:
intersect, setdiff, setequal, union
df <- do.call("rbind", ldf)
## Date_view_track factor created
df$D_V_T <- paste(df$Date, df$View, df$Track, sep='_')
df$D_V_T <- as.factor(df$D_V_T)
## Date_view factor created
df$D_V <- paste(df$Date, df$View, sep='_')
df$D_V <- as.factor(df$D_V)
head(df)
tail(df)
Add columns of metadata based on the D_V of each row
Add heading, pitch and d and v values